<?php

  /*

      TravianWAP
      Copyright (c) 2007-08 by Ananas - All rights reserved
      http://n00bz.biz/travianwap/
      Contact: uroskn@gmail.com

      --------------------------------------------------------------------------

      This program is free software: you can redistribute it and/or modify
      it under the terms of the GNU  General Public License as published by
      the Free Software Foundation, either version 3 of the License, or
      (at your option) any later version.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.

      You should have received a copy of the GNU  General Public License
      along with this program. If not, see http://www.gnu.org/licenses/.

  */

  define("MODULE_OK", 1);
  if (!defined("MAIN_UNIT")) die("h4xx0r");
  global $txt;
  
  $_SESSION["village"] = travian_extract_village_name($txt, True);
  printtop($txt);
  
  $res = travian_extract_resource_page_info($txt, True);

  if (strpos($txt, '<td><a href="build.php?gid=16"><img src="img/un/a/att1.gif" border="0"></a></td>') !== False)
  {
     $temp = substr($txt, strpos($txt, '<td><b class="c5 f10" align="right">&raquo; ') + strlen('<td><b class="c5 f10" align="right">&raquo; '));
     $count = substr($temp, 0, strpos($temp, '<'));
     $temp = substr($temp, strpos($temp, '<td class="f10"><span id=timer') + strlen('<td class="f10"><span id=timer'));
     $temp = substr($temp, strpos($temp, '>') + 1);
     $at = substr($temp, 0, strpos($temp, '<'));
     echo "<strong>$count attack</strong> - $at<br/><br/>";
  }

  //print_r($res["production"]);
  echo "{$res["production"][0]}|{$res["production"][1]}|{$res["production"][2]}|{$res["production"][3]}<br/><br/>";

  //print_r($res["fields"]);
  for ($i = 0; $i < 18; $i++)
  {
   /* // LOCALIZATION_USE is defined in travian parser (travian.php)
    if (defined("LOCALIZATION_USE"))
    {                              */
      // I heard of swich, but too late.
      if ($i == 3) echo "<br/>";
      else if ($i == 7) echo "<br/>";
      else if ($i == 11) echo "<br/>";
      else if ($i == 15) echo "<br/>";
      else if ($i != 0) echo "-";
      $str = NULL;
      switch ($res["fields"][$i][0])
      {
        case 1: $str = "WO "; break;
        case 2: $str = "CL "; break;
        case 3: $str = "IR "; break;
        case 4: $str = "C R"; break;
      }
      $str .= $res["fields"][$i][1];
      print_link("main.php?mod=construct&amp;id=".($i + 1)."&amp;ret=main".ps(), $str);
    /*}
    else echo "<anchor>{$res["fields"][$i]}<go href=\"main.php?mod=construct&amp;id=".($i + 1)."&amp;ret=main".ps()."\"/></anchor><br/>";  */
  }
  
  if (!empty($res["construction"][0]["title"]))
  {
    echo "<br/><br/>";
    for ($i = 0; $i <= 2; $i++)
    {
      if (!empty($res["construction"][$i]["title"]))
      {
        print_link("main.php?mod=direct_call&amp;file=dorf1&amp;".htmlspecialchars($res["construction"][$i]["url"])."&amp;return=main".ps(), "[X]");
        echo " ".$res["construction"][$i]["title"]."<br/>".pdate($res["construction"][$i]["end"]).
             " - ".pdate($res["construction"][$i]["endat"], False)."<br/>";
      }
    }
  }
  else echo "<br/>";

  echo "<br/>";

?>
